package com.android.smsmessing;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.android.smsmessing.adapter.HeaderAdapter;
import com.android.smsmessing.adapter.PeoplesAdapter;
import com.android.smsmessing.adapter.SeparatedListAdapter;
import com.android.smsmessing.model.PeopleVO;

public class PeopleActivity extends Activity {

	private ListView lsPeoples;
	private TableLayout tableLayout;
	private ArrayList<PeopleVO> peoples;
    public final static String ITEM = "view";  
    public Context context;
    public Map<String,?> createItem(View view) {  
        Map<String,View> item = new HashMap<String,View>();  
        item.put(ITEM, view);  
        return item;  
    }  
	@Override
	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		context = this;
         SeparatedListAdapter adapter = new SeparatedListAdapter(this);  
         adapter.addSection("搜索",new HeaderAdapter(this));  
         Bundle bundle = this.getIntent().getExtras();
         peoples = (ArrayList<PeopleVO>) bundle
         .get("peoples");
         PeoplesAdapter peopleAdapter = new PeoplesAdapter(this);
         peopleAdapter.setPeoples(peoples);
         adapter.addSection("联系人", peopleAdapter);  
   
         ListView list = new ListView(this);  
         list.setAdapter(adapter);  
         this.setContentView(list);  
         
         list.setOnItemClickListener(itemClickListener);
	}
	
	OnItemClickListener itemClickListener = new OnItemClickListener(){

		@Override
		public void onItemClick(AdapterView<?> convertView, View view, int position,
				long id) {
			 LinearLayout layout = (LinearLayout)view;
			 ImageView imgView = (ImageView) layout.getChildAt(0);
			 PeopleVO people = peoples.get(position - 3);
			if (people.isSelect) {
			imgView.setImageResource(android.R.drawable.checkbox_off_background);
		} else {
			imgView.setImageResource(android.R.drawable.checkbox_on_background);
		}
			people.isSelect = !people.isSelect;
		}

		
	};
	
}
